// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/unresolved/visitor.h>

namespace cantor::unresolved {

    class UnresolvedSelectStmt;
    class UnresolvedOrderByClause;
    class UnresolvedLimitClause;

    class UnresolvedUnionStmt : public UnresolvedVisitor<UnresolvedUnionStmt> {
    public:
        static constexpr const cantor::pb::ast::StmtType TYPE = cantor::pb::ast::StmtType::STMT_UNION;

        UnresolvedUnionStmt(const cantor::pb::ast::UnionStmt &node) :
                                                                     instance(node) {
        }

        UnresolvedUnionStmt(const cantor::pb::ast::Statement &node) : instance(node.union_stmt()) {
        }

        ~UnresolvedUnionStmt() override = default;

        const pb::Location& location_impl() const {
            return  instance.location();
        }

        const pb::Status &error_status_impl() const {
            return  instance.status();
        }

        bool distinct(bool f = false) const {
            if (instance.has_distinct()) {
                return instance.distinct();
            }
            return f;
        }

        bool select_stmts_size() const {
            return instance.select_stmts_size();
        }

        UnresolvedSelectStmt select_stmts(int i) const;

        bool has_order() const {
            return  instance.has_order();
        }

        UnresolvedOrderByClause order() const;

        bool has_limit() const {
            return  instance.has_limit();
        }

        UnresolvedLimitClause limit() const;

        cantor::pb::ast::SelectLock lock(cantor::pb::ast::SelectLock l= cantor::pb::ast::SL_NONE) const {
            if (instance.has_lock()) {
                return instance.lock();
            }
            return l;
        }

        bool is_in_braces(bool f = false) const {
            if (instance.has_is_in_braces()) {
                return instance.is_in_braces();
            }
            return f;
        }

        const cantor::pb::ast::UnionStmt &instance;
    };
} // namespace cantor::unresolved
